<?php
/**
 +---------------------------------------<br/>
 * 控制器:会员<br/>
 +---------------------------------------
 * @category membership
 * @package web.front.action
 * @author skygreen skygreen2001@gmail.com
 */
class Action_Member extends Action
{
    /**
     * 查看会员
     */
    public function info()
    {
        $cardno = HttpSession::get("cardno");
        $phone = HttpSession::get("phone");
        if(!$phone && !$cardno){
            $this->redirect("index","login");
        }
        $this->loadCss("resources/css/member_info.css");
        $this->loadJs("js/member_info.js");
        $api = new UtilApi();
        $data = $api->getMember($phone);
        $member = $data->data;
        if(!$cardno){
            if($member->card_no){
                HttpSession::set("cardno", $member->card_no);
                $openid = HttpSession::get("openid");
                $mb = Member::get_one("weixin='$openid'");
                $mb->code = $member->card_no;
                $mb->update();
            }
        }
        $this->view->set("member",$member);
        $this->view->set("site_name","会员中心");
    }
    /**
     * 编辑会员
     */
    public function edit()
    {
        $this->loadCss("resources/css/member_info.css");
        $this->loadJs("js/member_info.js");
        $this->view->set("site_name","会员中心");
        $phone = HttpSession::get("phone");
        $cardno = HttpSession::get("cardno");
        $data = UtilApi::getMember($phone);
        $member = $data->data;
        if (isset($member->gender)) {
            $member->user_gender = $member->gender;
        }
        $date = explode("-",$member->user_birthday);
        $this->view->set("tyear",$date[0]);
        $this->view->set("tmon",$date[1]);
        $this->view->set("tday",$date[2]);
        $this->view->set("member",$member);
    }

    public function ajaxEdit(){
        $data = array();
        $data['cardno']= isset($_POST['cardno'])?$_POST['cardno']:"";
        $data['passwd']= isset($_POST['passwd'])?$_POST['passwd']:"";
        $data['realname']= isset($_POST['realname'])?$_POST['realname']:"";
        $data['gender']= isset($_POST['gender'])?$_POST['gender']:"";
        $data['idnum']= isset($_POST['idnum'])?$_POST['idnum']:"";
        $data['phone']= isset($_POST['phone'])?$_POST['phone']:"";
        $data['mobile']= isset($_POST['mobile'])?$_POST['mobile']:"";
        $data['email']= isset($_POST['email'])?$_POST['email']:"";
        $data['province']= isset($_POST['province'])?$_POST['province']:"";
        $data['city']= isset($_POST['city'])?$_POST['city']:"";
        $data['area']= isset($_POST['area'])?$_POST['area']:"";
        $data['address']= isset($_POST['address'])?$_POST['address']:"";
        $data['zipcode']= isset($_POST['zipcode'])?$_POST['zipcode']:"";
        $data['ext_ids']= isset($_POST['ext_ids'])?$_POST['ext_ids']:"";
        $data['ext_values']= isset($_POST['ext_values'])?$_POST['ext_values']:"";
        $tyear = isset($_POST['tyear'])?$_POST['tyear']:"0000";
        $tmon = isset($_POST['tmon'])?$_POST['tmon']:"00";
        $tday = isset($_POST['tday'])?$_POST['tday']:"00";
        $data['birthday'] = $tyear."-".$tmon."-".$tday;
        $result = UtilApi::modify_member($data);
        echo $result;
        exit;

    }
    /**
     * 会员尊享
     */
    public function ruleRange(){
        $this->loadCss("resources/css/ruleRange.css");
        $type = array(
            1=>'消费送积分',
            2=>'充值送积分',
            3=>'充值送金额',
            4=>'特定时间消费送积分'
        );
        $api = new UtilApi();
        $rulerange1 = $api->rule_range(1);
        $data1 = $rulerange1->data;
        $rulerange2 = $api->rule_range(2);
        $data2 = $rulerange2->data;
        $rulerange3 = $api->rule_range(3);
        $data3 = $rulerange3->data;

        $this->view->set("data1",$data1);
        $this->view->set("data2",$data2);
        $this->view->set("data3",$data3);
    }
    /**
     * 删除会员
     */
    public function delete()
    {

    }
}

?>